<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('茶店库存列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <form id="formId">
            <input type="hidden" id="teaShopId" name="teaShopId" th:value="${teaShop.id}">
        </form>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "system/shop/teaShopInventory";

    $(function() {
        var options = {
            url: prefix + "/teaShopInventoryList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "茶店库存",
            columns: [{
                checkbox: true
            },
                {
                    field: 'rawMaterialId',
                    title: '原料编号'
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'description',
                    title: '描述'
                },
                {
                    field: 'amount',
                    title: '剩余数量'
                }
                ,
                {
                    field: 'amount2',
                    title: '消耗数量',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<input type="text" id="consumeAmount' + index + '"/>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function submitHandler() {
        var materialIds = $.table.selectFirstColumns();

        if (materialIds.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var deliverAmount = new Array();
        for (var i = 0; i < $("#materialAmounts").val(); i++) {
            var ans = document.getElementById("consumeAmount" + i).value;
            deliverAmount.push(ans);
        }

        var data = {"warehouseId": $("#warehouseId").val(), "teaShopId": $("#teaShopId").val(), "materialIds": materialIds.join(), "data": deliverAmount.join()};
        $.operate.save(prefix + "/warehouseInventory/deliverMaterial/selectDeliverMaterial", data);
    }
</script>
</body>
</html>